package com.dd.service.impl;

import com.dd.mapper.CustomerMapper;
import com.dd.model.Customer;
import com.dd.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 客户服务实现类
 */
@Service
public class CustomerServiceImpl implements CustomerService {
    
    @Autowired
    private CustomerMapper customerMapper;
    
    @Override
    public List<Customer> findAllCustomers() {
        return customerMapper.findAll();
    }
    
    @Override
    public Customer getCustomerById(Integer customerId) {
        return customerMapper.findById(customerId);
    }
    
    @Override
    public Customer getCustomerByEmail(String email) {
        return customerMapper.findByEmail(email);
    }
    
    @Override
    public List<Customer> findCustomersByName(String name) {
        return customerMapper.findByNameLike(name);
    }
    
    @Override
    @Transactional
    public boolean addCustomer(Customer customer) {
        return customerMapper.insert(customer) > 0;
    }
    
    @Override
    @Transactional
    public boolean updateCustomer(Customer customer) {
        return customerMapper.update(customer) > 0;
    }
    
    @Override
    @Transactional
    public boolean deleteCustomer(Integer customerId) {
        return customerMapper.deleteById(customerId) > 0;
    }
} 